package leetcode.剑指offer.again.剑指;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author ：zsy
 * @date ：Created 2022/9/26 3:32 PM
 * @description：
 */
public class 剑指_I_39_数组中出现次数超过一半的数字 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        public int majorityElement(int[] nums) {
            int len = nums.length;
            Arrays.sort(nums);
            return nums[len / 2];
        }

        public void quickSort(int[] nums, int left, int right) {
            if (left >= right) return;
            int l = left;
            int r= right;
            int pivot = nums[l];
            while (l < r) {
                while (l < r && nums[r] >= pivot) r--;
                nums[l] = nums[r];
                while (l < r && nums[l] <= pivot) l++;
                nums[r] = nums[l];
                nums[l] = pivot;
            }
            quickSort(nums, left, l - 1);
            quickSort(nums, l + 1, right);
        }
    }
}
